export function usePeriodicRequest(callback, interval = 1000, initialParams = {},num) {
    let timeoutId = null;
    let isRunning = false;
    let currentParams = { ...initialParams };

    const run = () => {
        if (!isRunning) return;
        callback(currentParams); // 调用函数并传递参数
        timeoutId = setTimeout(run, interval); // 递归调用自身
    };

    const startFetching = () => {
        isRunning = true;
        run();
    };

    const stopFetching = () => {
        isRunning = false;
        clearTimeout(timeoutId);
        timeoutId = null;
    };

    const updateParams = (newParams) => {
        currentParams = { ...currentParams, ...newParams };
    };

    return {
        startFetching,
        stopFetching,
        updateParams,
    };
}